package com.zrwl.poscloud.core.restapi.mobile;

import com.alibaba.fastjson.JSONObject;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.xo.service.TimeTableDetailService;
import com.zrwl.poscloud.xo.service.TimeTableService;
import com.zrwl.poscloud.xo.service.UserService;
import com.zrwl.poscloud.xo.vo.EmployeeVO;
import com.zrwl.poscloud.xo.vo.TimeTableDetailVO;
import com.zrwl.poscloud.xo.vo.TimeTableVO;
import com.zrwl.poscloud.xo.vo.UserEmployeeRVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请假管理 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-16
 */
@RestController
@Api(value = "课程表相关接口", tags = {"课程表相关接口"})
@RequestMapping("/course")
@Slf4j
public class CourseRestApi {
    @Autowired
    private TimeTableService timeTableService;
    @Autowired
    private TimeTableDetailService timeTableDetailService;
    @Autowired
    private UserService userService;
    @AuthorityVerify
    @ApiOperation(value = "获取课程表", notes = "获取课程表", response = String.class)
    @PostMapping("/getCourseInfo")
    public String getCourseInfo(@Validated({GetList.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取课程表: {}", timeTableVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        EmployeeVO employeeVO = JSONObject.parseObject(userEmployeeRVO.getEmployeeJsonData(), EmployeeVO.class);
        timeTableVO.setCompanyCode(employeeVO.getCompanyCode());
        timeTableVO.setDeptUid(employeeVO.getDeptUid());
        return ResultUtil.successWithData(timeTableService.getCourseInfo(timeTableVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "获取课程表明细", notes = "获取课程表明细", response = String.class)
    @PostMapping("/getCourseDetailInfo")
    public String getCourseDetailInfo(@Validated({GetList.class}) @RequestBody TimeTableDetailVO timeTableDetailVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取课程表明细: {}", timeTableDetailVO);
        UserEmployeeRVO userEmployeeRVO = userService.getMe().getUserEmployeeRVO();
        EmployeeVO employeeVO = JSONObject.parseObject(userEmployeeRVO.getEmployeeJsonData(), EmployeeVO.class);
        timeTableDetailVO.setCompanyCode(employeeVO.getCompanyCode());
        timeTableDetailVO.setDeptUid(employeeVO.getDeptUid());
        return ResultUtil.successWithData(timeTableDetailService.getCurriculumDetailInfo(timeTableDetailVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "启用课程", notes = "启用课程", response = String.class)
    @PostMapping("/enableCourse")
    public String enableCourse(@Validated({GetList.class}) @RequestBody TimeTableVO timeTableVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取课程表: {}", timeTableVO);
        return ResultUtil.successWithData(timeTableService.enableCourse(timeTableVO));
    }
}
